package com.ruoyi.mq.service.serviceImpl.Processor;

import com.alibaba.fastjson2.JSONObject;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.ruoyi.mq.service.MessageProcessor;
import com.ruoyi.system.domain.GwHomeSummarize;
import com.ruoyi.system.service.IGwHomeSummarizeService;
import com.ruoyi.system.service.ISysDeptService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.messaging.simp.SimpMessagingTemplate;
import org.springframework.stereotype.Component;

import java.util.Date;

/**
 * 发码量处理类
 */
@Component
public class CodeVolumeProcessor implements MessageProcessor {
    @Autowired
    private IGwHomeSummarizeService gwHomeSummarizeService;
    @Autowired
    private ISysDeptService deptService;
    @Autowired
    private  SimpMessagingTemplate messagingTemplate;

    public void processMessage(JSONObject message) {
        System.out.println(message);
        // 处理发码量
        // 创建 ObjectMapper 实例
//        ObjectMapper objectMapper = new ObjectMapper();
//
        // 转换为自定义对象
        String niot_id = message.getString("niot");
        if (niot_id == null) {
            return;
        }
        //查询首页汇总数据
      //  GwHomeSummarize gwHomeSummarize = gwHomeSummarizeService.selectGwHomeSummarizeByNodeIdentifier(niot_id);
        //如果为空则新增，有数据则更新

        GwHomeSummarize gwSummarize = new GwHomeSummarize();
        //设置节点标识
        gwSummarize.setNodeIdentifier(niot_id);
        gwSummarize.setCreateTime(new Date());
        gwSummarize.setCodesSentNumber(Long.valueOf(message.getString("data")));
        //新增数据
        gwHomeSummarizeService.insertGwHomeSummarize(gwSummarize);


    }

}
